/* ==================================================
*
* @Method: 		echeck
* @Describe:	check format of email
* =================================================== */
function echeck(d) {
    return /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(d);
}

/* ==================================================
*
* @Method: 		load_page
* @Describe:	load page with full url or apart url of website
* =================================================== */
function load_page(url) {
	if(url == ""){
		window.location.reload();
	}else {
		window.location.assign(url);
	}
	
}

/* ==================================================
*
* @Method: 		remove_utf8
* @Describe:	replace utf-8 character to alphabe character
* =================================================== */
function remove_utf8(str) {
	var from	= "àáạảãâầấậẩẫăằắặẳẵèéẹẻẽêềếệểễìíịỉĩòóọỏõôồốộổỗơờớợởỡùúụủũưừứựửữỳýỵỷỹđ";
	var to		= "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyd";
	
	for (var i = 0, l = from.length; i < l; i++) {
		str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
	}
	
	return str;
}

/* ==================================================
*
* @Method: 		numeric_press
* @Describe:	only numberic is allowed
* =================================================== */
function numeric_press(e)
{
	var keypressed = null;
	if (window.event)
	{
		keypressed = window.event.keyCode; //IE
	}
	else 
	{
		keypressed = e.which; //NON-IE, Standard
	}
	if (keypressed < 48 || keypressed > 57)
	{
		if (keypressed == 8 || keypressed == 127)
		{
		return;
		}
		return false;
	}
}

/* ==================================================
*
* @Method: 		keypress_alphanumberic
* @Describe:	only alphabet and numberic is allowed, not special characters
* =================================================== */
function keypress_alphanumberic(event) {

    //prevent user press "'" character
    if (event.keyCode == 222)
        return false;

    //Alow user press tab in firefox
    if (event.keyCode == 9)
        return true;
    //Alow user press tab in firefox
    if (event.keyCode == 13)
        return true;

    var k;
    document.all ? k = event.keyCode : k = event.which;
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}

/* ==================================================
*
* @Method: 		format_currency
* @Describe:	return string with currency format when user typing number
* =================================================== */
function format_currency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "";
	num = Math.abs(num);
	num = Math.floor(num*100+0.50000000001);
	num = Math.floor(num/100).toString();
	if(num==0)
		num = "";
	for (var i = 0; i < Math.floor(( num.length -(1+i))/3); i++){
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}
	return (num);
}

/**
 * Set all status of child-checkboxes as general checkbox
 *
 * @author  TuanNguyen
 * @version Created 2015-04-05
 * @param   HTMLElement element
 * @param   string      lbl_validationId
 * @return  void
 */
function validation_empty( element, lbl_validationId)
{
    if( $.trim(element.value) == '' ) {
        $('#'+lbl_validationId).fadeIn('slow', 'linear');
    } else {
        $('#'+lbl_validationId).fadeOut();
    }
}//End validation_empty


/**
 * Set all status of child-checkboxes as general checkbox
 *
 * @author  TuanNguyen
 * @version Created 2015-04-05
 * @param   HTMLElement generalCheckbox
 * @param   string      childCheckboxName
 * @return  void
 */
function setGeneralStatusOfCheckboxes( generalCheckbox, childCheckboxName )
{
    //Init
    var b_generalStatus = generalCheckbox.checked;

    //loop all child-checkboxes to set status 
    $("input[name='" + childCheckboxName + "']").each( function() {
        $(this).attr('checked', b_generalStatus);
    });
}